﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Register : System.Web.UI.Page
{
    SqlConnection conn;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
    string strconn;

    protected void Page_Load(object sender, EventArgs e)
    {
        txtpass.Attributes["value"] = txtpass.Text;
        txtrepass.Attributes["value"] = txtrepass.Text;
        strconn = WebConfigurationManager.ConnectionStrings["photoconnection"].ToString();
        conn = new SqlConnection(strconn);
    }

    protected void lbregister_Click(object sender, EventArgs e)
    {
        try
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
            else
                conn.Open();
            cmd = new SqlCommand("pdinsert", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@username", SqlDbType.NVarChar).Value = txtuser.Text;
            cmd.Parameters.Add("@password", SqlDbType.NVarChar).Value = txtpass.Text;
            cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = txtname.Text;
            cmd.Parameters.Add("@Age", SqlDbType.Int).Value = Convert.ToInt32(txtage.Text);
            cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = txtemail.Text;
            cmd.Parameters.Add("@Country", SqlDbType.NVarChar).Value = txtcountry.Text;
            string img = FileUpload1.FileName.ToString();
            //cmd.Parameters.AddWithValue("@image", image);
            cmd.Parameters.Add("@ImageUpload", SqlDbType.NVarChar).Value = "~\\images\\" + img;
            cmd.ExecuteNonQuery();
            FileUpload1.SaveAs(Server.MapPath("~\\images\\" + img));
            Response.Redirect("success.aspx");
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            conn.Close();
        }
    }
    protected void lbreset_Click(object sender, EventArgs e)
    {
        txtuser.Text = "";
        txtrepass.Text = "";
        
        txtpass.Text = "";
        txtname.Text = "";
        txtemail.Text = "";
        txtcountry.Text = "";
        txtage.Text = "";
    }
}